package com.xoa.controller.workflow;

import com.xoa.model.enclosure.Attachment;
import com.xoa.service.workflow.flowUtil.FlowUtilService;
import com.xoa.util.AjaxJson;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by zhanghangning on 2019/3/28.
 */
@Controller
@RequestMapping("/flowUtil")
public class FlowUtilController {

    @Autowired
    FlowUtilService flowUtilService;

    // 导出PDF
    @ResponseBody
    @RequestMapping("/htmlFormToPDF")
    public ToJson<Attachment> htmlFormTOPDF(HttpServletRequest request, HttpServletResponse response, Integer runId, String module,String htmlContent){
        return flowUtilService.htmlFormTOPDF(request, response, runId, module, htmlContent);
    }

    /**
     * 创建者: 张航宁
     * 创建日期：2019/02/11
     * 方法介绍: 工作流附件转公告接口
     */
    @ResponseBody
    @RequestMapping("/flowAttach2Other")
    public ToJson<Attachment> flowAttach2Other(HttpServletRequest request, Integer runId, String module){
        return flowUtilService.flowAttach2Other(request,runId,module);
    }

    /**
     * @接口说明: 工作流表单和附件转存文件柜接口
     * @日期: 2020/4/17
     * @作者: 张航宁
     */
    @ResponseBody
    @RequestMapping("/saveToFile")
    public ToJson<Attachment> saveToFile(HttpServletRequest request, Integer runId,String module,String fileName ,String htmlContent,Integer sortId,String formAttachment){
        return flowUtilService.saveToFile(request, runId, module, fileName, htmlContent, sortId, formAttachment);
    }

    /**
     * 创建者: 李金昊
     * 创建日期：2019/04/11
     * 方法介绍: 内部分发 公文正文转附件
     */
    @ResponseBody
    @RequestMapping("/flowAttachDocument")
    public ToJson<Attachment> flowAttachDocument(HttpServletRequest request, Integer runId, String module){
        return flowUtilService.flowAttachDocument(request,runId,module);
    }

    /**
     * 创建者: 李金昊
     * 创建日期：2019/05/9
     * 方法介绍: 内部分发 公文正文转附件   type 1 doc   2 pdf
     */
    @ResponseBody
    @RequestMapping("/flowAttachDocOrPdf")
    public ToJson<Attachment> flowAttachDocOrPdf(HttpServletRequest request, Integer runId, String module, Integer type){
        return flowUtilService.flowAttachDocOrPdf(request,runId,module,type);
    }

    @ResponseBody
    @RequestMapping("/flowAttachDocumentTitle")
    public ToJson<Attachment> flowAttachDocumentTitle(HttpServletRequest request, Integer runId){
        return flowUtilService.flowAttachDocumentTitle(request,runId);
    }


    @ResponseBody
    @RequestMapping("/getAllDocument")
    public AjaxJson getAllDocument(Integer flowId){
        return flowUtilService.getAllDocument(flowId);
    }
}
